package com.geen.tuoke.utils

import android.app.Activity
import com.geen.tuoke.R
import com.qmuiteam.qmui.skin.QMUISkinManager
import com.qmuiteam.qmui.widget.dialog.QMUIDialog
import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction

object QMDialogUtils {

    var qmuiDialog: QMUIDialog? = null

    interface DialogCallBack {
        fun clickSure()
        fun clickCancel()
    }

    fun showTipsDialog(
        activity: Activity,
        title: String? = "提示",
        message: String,
        callBack: DialogCallBack
    ) {
        if (qmuiDialog != null) {
            qmuiDialog = null
        }
        qmuiDialog = QMUIDialog.MessageDialogBuilder(activity)
            .setTitle(title)
            .setMessage(message)
            .setSkinManager(QMUISkinManager.defaultInstance(activity))
            .addAction(
                R.string.text_cancel
            ) { dialog, index ->
                callBack.clickCancel()
                dialog.dismiss()
                qmuiDialog = null
            }
            .addAction(
                0,
                R.string.text_sure,
                QMUIDialogAction.ACTION_PROP_NEGATIVE
            ) { dialog, index ->
                dialog.dismiss()
                callBack.clickSure()
                qmuiDialog = null
            }
            .create()
        qmuiDialog?.show()
    }
}